/**********************分页函数***********************/
//nums:总记录数,num：当前页数,name：调用的函数,pages总页数,show_pages:显示多少条页数(偶数),
function show_page(nums,num,name,pages,show_pages)
{
	var nums=parseInt(nums);
	var num=parseInt(num);
	var pages=parseInt(pages);
	var show_pages=parseInt(show_pages);
	var type=parseInt(type);

	//var tmp_page='<span>总记录数:<font color=red>'+nums+'</font>条</span>&nbsp;&nbsp;';
	var tmp_page='';

	if(num>1)
	{
		tmp_page+="<a href='javascript:void(0);' onclick='"+name+"(1)'>首页</a>&nbsp;";
		page=num-1;
		tmp_page+="<a href='javascript:void(0);' onclick='"+name+"("+page+")'>上一页</a>&nbsp;";
	}

	var start	=	1;
	var end		=	pages;

	//只有总页数大于要显示的页数才有用
	if(show_pages<pages)
	{

		tmp_show_pages	=	show_pages/2;
		//判断起始位置
		if(num-tmp_show_pages<=1)
		{
			start	=	1;
			end		=	show_pages;
		}
		else
		{
			start	=	num-tmp_show_pages;
			end		=	num+tmp_show_pages;
		}
		
		//判断结束位置
		if((num+tmp_show_pages)>pages)
		{
			start	=	num-(show_pages-(pages-num));
			end		=	pages;
		}
	}

	for(var j=start;j<=end;j++) 
	{
		if(j==num)
		{
			tmp_page+="<a style='color:red;'>"+j+"</a>&nbsp;";
		}
		else
		{
			tmp_page+="<a href='javascript:void(0);' onclick='"+name+"("+j+")'>"+j+"</a>&nbsp;";
		}
	}

	if(num<pages)
	{
		page=num+1;
		tmp_page+="<a href='javascript:void(0);' onclick='"+name+"("+page+")'>下一页</a>";

		tmp_page+="&nbsp;<a href='javascript:void(0);' onclick='"+name+"("+pages+")'>尾页</a>";
	}
	return tmp_page;
}

function show_page_select(nums,num,name,pages,show_pages)
{
	var tmp_page="<select  id='select_page' onchange='change_page("+name+")'>";
	for(var i=1;i<=pages;i++) 
	{
		if(i==num)
		{
			tmp_page+="<option value="+i+" selected>"+i;
		}
		else
		{
			tmp_page+="<option value="+i+">"+i;
		}
	}
	tmp_page+="</select>";
	return tmp_page;
}

function change_page(name)
{
	name($('#select_page').val());
}

/***********获得输入参数***************/
function get_url_parm(tmp_v)
{
	var tmp=decodeURIComponent(Request.QueryString(tmp_v));
	if(tmp!= null && tmp!="undefined" && tmp!="null" && tmp!="请选择" && tmp!="00")
		return tmp;
	else
		return "";
}

function init_jl_div()
{
	jl_tag=1;
	var tmp='<div id="left_dh">精炼您的检索</div>';
	for(var item in jl_array)
	{
		tmp+='<div class="box leftbox">';

		tmp+='<span>'+jl_array[item]+'</span>';
		//tmp+='<dd class="sub_dd">';
		tmp+="	<ul id='show_jl_"+item+"' class='subul' style=''>载入中...</ul>";
		tmp+="	<ul id='show_jl_"+item+"1' class='subul' style='display:none;'></ul>";
		//tmp+='</dd>';

		tmp+='</div>';
	}
	$('#c_left').html(tmp);
}

/**************聚类操作*********************/
//tag：1时表示按指定顺序显示
//tag_one:显示指定的
function show_jl(tmp_str,tmp_div,tmp_array,show_name)
{
	$("#show_jl_"+tmp_div).empty();

	try
	{
		for(i=0;i<tmp_str.length && i<8;i++)
		{
			$("#show_jl_"+tmp_div).append(get_jl_content(eval("tmp_str[i]."+show_name),tmp_div,tmp_array,tmp_str));
		}
		/***********************************/
		if(tmp_str.length>10 )
		{
			$("#show_jl_"+tmp_div).append("<li id='show_jl_"+tmp_div+"_more'><a href='javascript:void(0);' onclick='change_more(1,\""+tmp_div+"\")'>更多选项...</a></li>"); // 把返回的数据添加到页面上

				for(i=8;i<tmp_str.length;i++)
				{
					//alert(get_jl_content(eval("tmp_str[i]."+show_name),tmp_div,tmp_array,tmp_str))
					$("#show_jl_"+tmp_div+"1").append(get_jl_content(eval("tmp_str[i]."+show_name),tmp_div,tmp_array,tmp_str));
				}

			$("#show_jl_"+tmp_div+"1").append("<li><a href='javascript:void(0);' onclick='change_more(2,\""+tmp_div+"\")'>收起选项...</a></li>"); // 把返回的数据添加到页面上
		}
	}
	catch(e){
		$("#show_jl_"+tmp_div).html('');
	}
}

function change_more(type,tmp_name)
{
	if(type==1){$("#show_jl_"+tmp_name+'1').show();$("#show_jl_"+tmp_name+'_more').hide();}
	else{$("#show_jl_"+tmp_name+'1').hide();$("#show_jl_"+tmp_name+'_more').show();}
}
function get_jl_content(tmp,tmp_div,tmp_array,tmp_str)
{	
	var tmps=tmp.replace(/\'/ig,"\\'");
	if(tmp_div=='tree_view_id'){
		for(var item in tree_view_arr){
			if(tree_view_arr[item]['id']==tmps){
				name=tree_view_arr[item]['title'];
			}
		}
	}else{
		var name=tmps;
	}
	if(tmps!=undefined && tmps.length>0)
	{
		return '<li><a href="javascript:void(0);" onclick="change_url(\''+tmp_div+'\',\''+tmps+'\')">'+name+'</a>('+tmp_str[i].total+')</li>'; // 把返回的数据添加到页面上
	}
	else
	{
		return '';
	}
}

/*************聚类获得参数***************/
function get_url_jl_parm(tmp_t,tmp_value,change_str)
{
	if(change_str==tmp_t)
	{
		return tmp_t+"="+encodeURIComponent(tmp_value);
	}
	else
	{
		return tmp_t+"="+Request.QueryString(tmp_t);
	}
}

//获取当前目录
function show_left_c(id)
{
	var daohang2='<span class="name"><a href="index.html">图书馆首页</a>&nbsp;&gt;&nbsp;';
	for(var item in tree_view_arr)
	{
		if(tree_view_arr[item].Id==id)
		{
			if(id==1){
				if(tree_view_arr[item].Type==1){
					var tmp_url='article.htm?id='+tree_view_arr[item].Id;
				}else{
					var tmp_url='article.htm?id=12&fid=1';
				}
				$('#menu_1').addClass('menu_on');
			}else if(id==24){
				if(tree_view_arr[item].Type==1){
					var tmp_url='article.htm?id='+tree_view_arr[item].Id;
				}else{
					var tmp_url='article.htm?id=25&fid=24';
				}
				$('#menu_2').addClass('menu_on');
			}else if(id==37){
				if(tree_view_arr[item].Type==1){
					var tmp_url='article.htm?id='+tree_view_arr[item].Id;
				}else{
					var tmp_url='article.htm?id=39&fid=37';
				}
				$('#menu_3').addClass('menu_on');
			}else if(id==49){
				if(tree_view_arr[item].Type==1){
					var tmp_url='article.htm?id='+tree_view_arr[item].Id;
				}else{
					var tmp_url='article.htm?id=85&fid=49';
				}
				$('#menu_4').addClass('menu_on');
			}else{
				for(var item1 in tree_view_arr)
				{
					if(tree_view_arr[item1].Id==tree_view_arr[item].Parent_id){			
						if(tree_view_arr[item].Parent_id==1){
							$('#menu_1').addClass('menu_on');
							if(tree_view_arr[item1].Type==1){
								var tmp_url='article.htm?id='+tree_view_arr[item1].Id;
							}else{
								var tmp_url='article.htm?id=12&fid=1';
							}
						}else if(tree_view_arr[item].Parent_id==24){
							$('#menu_2').addClass('menu_on');
							if(tree_view_arr[item].Type==1){
								var tmp_url='article.htm?id='+tree_view_arr[item1].Id;
							}else{
								var tmp_url='article.htm?id=26&fid=24';
							}
						}else if(tree_view_arr[item].Parent_id==37){
							$('#menu_3').addClass('menu_on');
							if(tree_view_arr[item].Type==1){
								var tmp_url='article.htm?id='+tree_view_arr[item1].Id;
							}else{
								var tmp_url='article.htm?id=39&fid=37';
							}
						}else if(tree_view_arr[item].Parent_id==49){
							$('#menu_4').addClass('menu_on');
							if(tree_view_arr[item].Type==1){
								var tmp_url='article.htm?id='+tree_view_arr[item1].Id;
							}else{
								var tmp_url='article.htm?id=85&fid=49';
							}
						}
						daohang2+='<a href="'+tmp_url+'">'+tree_view_arr[item1].Title+'</a>&nbsp;&gt;&nbsp;';
					}
					var tmp_url=document.URL;
				}
			}
			daohang2+='<a href="'+tmp_url+'">'+tree_view_arr[item].Title+'</a>&nbsp;&gt;&nbsp;';
		}
	}
	return daohang2;
}
//获取左侧栏目
function show_left_l(id,aid)
{
	var content='';
	var flag=0;	
	if(id==0){id=aid}
	for(var item in tree_view_arr)
	{	
		var son_div='';	
		if(tree_view_arr[item].Id==id) //有子分类  //屏蔽90分钟讲座 id 32
		{
			if(tree_view_arr[item].Parent_id!=0  && id!=3){
				for(var item1 in tree_view_arr){
					if(tree_view_arr[item1].Id==tree_view_arr[item].Parent_id){
						content+='<div class="side_list_head">'+tree_view_arr[item1].Title+'</div>';
					}
					if(tree_view_arr[item1].Parent_id==tree_view_arr[item].Parent_id &&tree_view_arr[item1].Id!=32){
						var flag1=0;	
						if(tree_view_arr[item1].State!=0){				
							if(tree_view_arr[item1].Type==1 || tree_view_arr[item1].Type==3){
								tmp_url="article.htm?id="+tree_view_arr[item1].Id+"&fid="+tree_view_arr[item1].Parent_id;
							}else if(tree_view_arr[item1].Type==2){
								tmp_url="list_view.htm?id="+tree_view_arr[item1].Id+"&fid="+tree_view_arr[item1].Parent_id;
							}else if(tree_view_arr[item1].Type==5){	
								tmp_url="database.htm?id="+tree_view_arr[item1].Id+"&fid="+tree_view_arr[item1].Parent_id;
							}else{
								flag++;
								flag1=1;
								son_div=get_dfl_div(tree_view_arr[item1].Id);
							}
							if(id==tree_view_arr[item1].Id){
								var clas="choose";
								var show='style="display:block;"';
							}else{
								var clas="father";
								var show='style="display:none;"';
							}
							if(flag1!=0){
								content+='<div id="1" class="'+clas+'"  onclick="switchs('+flag+',\''+get_dfl_url(tree_view_arr[item1].Id)+'\');">'+getInterceptedStr(tree_view_arr[item1].Title,20)+'</div><div id="content'+flag+'" '+show+'>'+son_div+'</div>';
							}else{
								content+='<div id="1" class="'+clas+'"><a href="'+tmp_url+'" title="'+tree_view_arr[item1].Title+'" '+tree_view_arr[item1]['Open']+'>'+getInterceptedStr(tree_view_arr[item1].Title,20)+'</a></div>';
							}
						}
					}
				}
				break;
			}else{
				content+='<div class="side_list_head">'+tree_view_arr[item].Title+'</div>';
			}
		}
		else if(tree_view_arr[item].Parent_id==id && (id==1 || id==24 || id==37 || id==49 || id==55 || id==3)  &&tree_view_arr[item].Id!=32)
		{//没有子分类
			var flag1=0;	
			if(tree_view_arr[item].State!=0){			
				if(tree_view_arr[item].Type==1 || tree_view_arr[item].Type==3){
					tmp_url="article.htm?id="+tree_view_arr[item].Id+"&fid="+tree_view_arr[item].Parent_id;
				}else if(tree_view_arr[item].Type==2){
					tmp_url="list_view.htm?id="+tree_view_arr[item].Id+"&fid="+tree_view_arr[item].Parent_id;
				}else if(tree_view_arr[item].Type==5){	
					tmp_url="database.htm?id="+tree_view_arr[item].Id+"&fid="+tree_view_arr[item].Parent_id;
				}else{
					flag++;
					flag1=1;
					son_div=get_dfl_div(tree_view_arr[item].Id);
				}
				if(aid==tree_view_arr[item].Id){
					var clas="choose";
				}else{
					var clas="father";
				}
				if(flag1!=0){
					content+='<div id="1" class="'+clas+'"  onclick="switchs('+flag+',\''+get_dfl_url(tree_view_arr[item].Id)+'\')">'+getInterceptedStr(tree_view_arr[item].Title,20)+'</div><div id="content'+flag+'" style="display:none;">'+son_div+'</div>';
				}else{
					content+='<div id="1" class="'+clas+'"><a href="'+tmp_url+'" title="'+tree_view_arr[item].Title+'" '+tree_view_arr[item]['Open']+'>'+getInterceptedStr(tree_view_arr[item].Title,20)+'</a></div>';
				}
			}
		}
	}
	return content;
}
/***************大分类处理****************/
function get_dfl_url(id){
	var url='';
	for(var item in tree_view_arr)
	{	
		if(tree_view_arr[item].Parent_id==id){
			var son_id=tree_view_arr[item].id;		
			if(tree_view_arr[item].Type==1){
				url="article.htm?id="+tree_view_arr[item].Id+"&fid="+tree_view_arr[item].Parent_id;break;
			}else if(tree_view_arr[item].Type==2){	
				url="list_view.htm?id="+tree_view_arr[item].Id+"&fid="+tree_view_arr[item].Parent_id;break;
			}else if(tree_view_arr[item].Type==5){	
				url="database.htm?id="+tree_view_arr[item].Id+"&fid="+tree_view_arr[item].Parent_id; break;
			}
		}
	}
	return url;
}

/***************大分类处理****************/
function get_dfl_div(id){
	var url='';
	var son_l='';
	for(var item in tree_view_arr)
	{	
		if(tree_view_arr[item].Parent_id==id){
			var son_id=tree_view_arr[item].id;		
			if(tree_view_arr[item].Type==1||tree_view_arr[item].Type==3){
				url="article.htm?id="+tree_view_arr[item].Id+"&fid="+tree_view_arr[item].Parent_id;
			}else if(tree_view_arr[item].Type==2){	
				url="list_view.htm?id="+tree_view_arr[item].Id+"&fid="+tree_view_arr[item].Parent_id;
			}else if(tree_view_arr[item].Type==5){	
				url="database.htm?id="+tree_view_arr[item].Id+"&fid="+tree_view_arr[item].Parent_id;
			}
			son_l+='<div class="son"><a href="'+url+'" '+tree_view_arr[item]['Open']+'>'+getInterceptedStr(tree_view_arr[item].Title,20)+'</a></div>';
		}
	}
	return son_l;
}
//得到焦点时触发事件
function OnFocusFun(element,elementvalue)
{
    if(element.value==elementvalue)
    {
        element.value="";
        element.style.color="#000";
    }
}
//离开输入框时触发事件
function OnBlurFun(element,elementvalue)
{
    if(element.value==""||element.value.replace(/\s/g,"")=="")
    {
        element.value=elementvalue;    
        element.style.color="#999";
    }
}

//判断字符的长度
function strlen(str){  
    var len = 0;  
    for (var i=0; i<str.length; i++) {   
     var c = str.charCodeAt(i);   
    //单字节加1    
     if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {   
       len++;   
     }   
     else {   
      len+=2;   
     }   
    }   
    return len;  
}
//截取字符
function getInterceptedStr(sSource, iLen)
{
    if(sSource.replace(/[^\x00-\xff]/g,"xx").length <= iLen)
    {
        return sSource;
    }

    var str = "";
    var l = 0;
    var schar;
    for(var i=0;schar=sSource.charAt(i);i++)
    {
        str += schar;
        l += (schar.match(/[^\x00-\xff]/) != null ? 2 : 1);
        if(l >= iLen)
        {
            break;
        }
    }

    return str;
}

//将日期 2012-4-25 转换成 4/25
function cut_date(str){
	var string=str.split('-');
	return string[1]+'/'+string[2];
}